package management;

import java.io.Serializable;

/**
 * 成绩实体类，关联学生和课程，包含分数
 */
public class Score implements Serializable {
    private Student student;  // 关联学生
    private Course course;    // 关联课程
    private double score;     // 分数

    public Score(Student student, Course course, double score) throws InvalidScoreException {
        this.student = student;
        this.course = course;
        setScore(score);  // 初始化时校验分数
    }

    // 分数设置：校验范围0-100
    public void setScore(double score) throws InvalidScoreException {
        if (score < 0 || score > 100) {
            throw new InvalidScoreException(score);
        }
        this.score = score;
    }

    // Getter方法
    public Student getStudent() { return student; }
    public Course getCourse() { return course; }
    public double getScore() { return score; }

    // 重写toString：包含学号、班级、课程编号、学分
    @Override
    public String toString() {
        return student.getName() + "（学号：" + student.getStudentId() + "，班级：" + student.getClassName() + "）- " +
               course.getName() + "（编号：" + course.getCourseId() + "，学分：" + course.getCredit() + "）：" +
               score + "分";
    }
}